/* 
题目1 ==================================================
*/
console.log(maxNum());
function maxNum() {
    let num1 = userInputNumberDetail('请输入第一个数字：');
    let num2 = userInputNumberDetail('请输入第二个数字：');
    return num1 < num2 ?num2:num1
}
/* 
题目2 ==================================================
*/
/* let str = userInputArr(['a','b','c','d','A','B','C','D'],`请输入 a、b、c、d,获取对应的季节：`,`请输入a b c d中的一个！`);
switch (str) { 
    case 'a':
        console.log('春');
        break;
    case 'A':
        console.log('春');
        break;
    case 'b':
        console.log('夏');
        break;
    case 'B':
        console.log('夏');
        break;
    case 'c':
        console.log('秋');
        break;
    case 'C':
        console.log('秋');
        break;
    case 'd':
        console.log('冬');
        break;
    case 'D':
        console.log('冬');
        break;
    default:
        console.log('err');
        break;
}
 */

/* 

题目3 ==================================================

*/
/* console.log(sum());
function sum(min = 1, max = 100) {
    let sum = 0;
    for (let i = min;i <= max;i++) {
        i % 2 ? `` : sum += i;
    }
    return sum;
} */

/* 

题目4 ==================================================

*/
/* let arr = [11, 39, 24, 45, 12, 1];
let min = arr[0], max = min;
for (let i = 0;i < arr.length;i++) {
    if (arr[i] > max) max = arr[i]
    if (arr[i] < min) min = arr[i]
}
console.log(`最大值：${max}最小值：${min}`);
 */
/* 

题目5 ==================================================

*/
/* console.log(even([71,22,63,34,15]));
function even(arr = []) {
    let num = 0;
    for (let i = 0;i < arr.length;i++) {
       arr[i]%2?``:num++
    }
    return num;
}  */


/* 

题目6 ==================================================

*/

/* let list = {goodsName:'电脑', price:6000, leftCount:99}
list.price = 5999;
console.log(list);// 题目要求输出对象 */

/* 

题目7 ==================================================

*/

/* let arr = []
for (let i = 0;i < 5;i++) {
   arr.push(parseInt(Math.random()*10)+1)
}
console.log(arr); */








/* 
######## 工具函数 #######
*/
//仅允许输入数字,包含空输入的说明文字
function userInputNumberDetail(hintInfo = `请输入数字：`, errInfoNaN = `非数字！`, errInfoNull = `输入为空！`) {
    let inputStr;
    for (let i = true; i ;) {
        inputStr = prompt(hintInfo);
        !inputStr ? alert(errInfoNull) : +inputStr ? i = false : inputStr == 0 ? i = false : alert(errInfoNaN);
    }
    return +inputStr;
}
//仅可以输入给定的数组内容
function userInputArr(arr = [],hintInfo = `请输入：`,errQualifiedInfo = `非限定字符！`, errInfo = `输入为空！`) {
    let inputStr;
    for (let i = true; i ;) {
        inputStr = prompt(hintInfo);
        if (!inputStr) {
            alert(errInfo)
        } else { 
            for (let j = 0;j < arr.length;j++) {
                if (inputStr === arr[j] + ``) { 
                    i = false;
                    break;
                }
            }
            if(i)alert(errQualifiedInfo)
        }
    }
    return inputStr;
}